package com.bing.util;

import com.bing.beans.Person;
import com.bing.sina.TaoListener;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

/**
 * Created by kaibb on 14-8-19.
 */
public class PersonParse implements Runnable {
    private String html;

    private Person person;

    private TaoListener taoListener;

    private static final Logger logger = LoggerFactory.getLogger(PersonParse.class);

    public PersonParse(String html, Person person, TaoListener taoListener) {
        this.html = html;
        this.person = person;
        this.taoListener = taoListener;
    }


    @Override
    public void run() {
        Document doc = Jsoup.parse(html);
        String guanZhu_follow_weibo = doc.select(".user_atten").get(0).text();
        TaoMath.setGuanZhu_fans_weibo(person, guanZhu_follow_weibo);
        Statistics.tongji(taoListener);
        String userName = doc.select(("div.profile_top div.pf_name span.name")).get(0).text();
        Elements star = doc.select("div.pf_info_right div.pf_star_info p");
        if (star.size() != 0) {
            TaoMath.setPersonRzJiFen(person, star.get(0).text());
        } else {
            Elements pf_verified = doc.select("div.pf_info_right  div.pf_verified img");
            if (pf_verified.size() != 0) {
                person.setRenZheng(pf_verified.get(0).attr("title"));
            } else {
                Elements identity = doc.select("div.pf_info_right  div.pf_info_identity div.identity_img a img");
                if (identity.size() != 0) {
                    person.setRenZheng(identity.get(0).attr("title"));
                }
            }
        }
        try {
            String levelInfo = doc.select("div.level div.level_info").get(0).text();
            TaoMath.setLevel(person, levelInfo);
        } catch (Exception e) {

        }
        person.setUserName(userName);
        person.setCreatedTime(new Date());
    }
}
